<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>加密解密</title>
</head>
<body>
MAC：
<br>
<input id="mac"/>
<br>
内容：
<br>
<textarea id="data" rows="5" cols="100"></textarea>
<br>
<button onclick="mqttCodeEncrypt()">加密</button>
<button onclick="mqttCodeDecrypt()">解密</button>
<br><br>
返回结果：
<br>
<textarea id="backData" rows="5" cols="100"></textarea>

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.js"></script>
<script>

  function mqttCodeEncrypt() {
    var command = document.getElementById("data").value
    var mac = document.getElementById("mac").value
    $.ajax({
      type:'GET',
      url:'http://' + window.location.host + '/smartPhone/mqttCodeEncrypt', // 'http://127.0.0.1:8080'  http://139.224.13.75:8082
      // url:'http://127.0.0.1:8080/smartPhone/mqttCodeEncrypt', // 'http://127.0.0.1:8080'  http://139.224.13.75:8082
      data:{command, mac},
      dataType:'JSON',
      error:function(){
        console.log('加密失败');
      },
      success:function(res){
        if(res.code===200){
          $("#backData").text(res.data);
        }else{
          console.log(res.msg);
        }
      }
    });
  }

  function mqttCodeDecrypt() {
    debugger
    var data = document.getElementById("data").value
    var mac = document.getElementById("mac").value
    $.ajax({
      type:'GET',
      url:'http://' + window.location.host + '/smartPhone/mqttCodeDecrypt', // 'http://127.0.0.1:8080'  http://139.224.13.75:8082
      // url:'http://127.0.0.1:8080/smartPhone/mqttCodeDecrypt', // 'http://127.0.0.1:8080'  http://139.224.13.75:8082
      data:{data, mac},
      dataType:'JSON',
      error:function(){
        console.log('解密失败');
      },
      success:function(res){
        if(res.code===200){
          $("#backData").text(res.data);
        }else{
          console.log(res.msg);
        }
      }
    });
  }

</script>
</body>
</html>
